<template>
  <view class="licence_example_page">
    <u-navbar autoBack fixed placeholder bgColor="#fff">
      <template #left>
        <view class="navBar">
          <u-icon name="arrow-left" color="#000" size="18"></u-icon>
          <text class="nav_title">上传资料</text>
        </view>
      </template>
    </u-navbar>
    <scroll-view scroll-y class="content" :style="{ height: `calc(100% - ${navBarHeight}px)` }">
      <view class="scroll_list">
        <view class="example_title">营业执照照片示例</view>
        <view class="example_detail">照片需方向正确，无倾泄、无抖动，并保证文字清晰可见、露出国徽</view>
        <view v-for="(item, index) in exampleList" :key="index" class="image_list">
          <view class="title">{{item.name}}</view>
          <image :src="item.url" mode="widthFix"></image>
        </view>
      </view>
    </scroll-view>
    <view class="footer">
      <u-button type="primary" shape="circle" text="拍摄照片" @click="getImage('camera')"></u-button>
      <u-button type="primary" shape="circle" text="相册选择照片" @click="getImage('album')"></u-button>
    </view>
  </view>
</template>

<script>

import {uploadImg} from "@/api/system/user";

export default {
  data() {
    return {
      exampleList: [
        {
          name: '营业执照（竖版）',
          url: require('@/static/img/shop/licence_01.png')
        },
        {
          name: '企业法人营业执照（横版）',
          url: require('@/static/img/shop/licence_02.png')
        },
        {
          name: '个体商业户营业执照（横版）',
          url: require('@/static/img/shop/licence_03.png')
        }
      ]
    }
  },
  computed: {
    navBarHeight () {
      const platform = uni.getSystemInfoSync().platform
      const statusBarHeight = uni.getSystemInfoSync().statusBarHeight
      let navHeight = 0
      if (['ios', 'devtools'].includes(platform)) {
        navHeight = 44
      } else {
        navHeight = 48
      }
      return navHeight + statusBarHeight
    }
  },
  methods: {
    getImage (sourceType) {
      uni.chooseMedia({
        sourceType: [sourceType],
        count: 1,
        success: function (res) {
          const tempFilePath = res.tempFiles[0].tempFilePath
          uploadImg({
            filePath: tempFilePath
          }).then(res => {
            const url = res.data.url
            const pages = getCurrentPages()
            const prevPage = pages[pages.length - 2]
            prevPage.$vm.licenceUrl = url
            uni.navigateBack()
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.licence_example_page {
  width: 100vw;
  height: 100vh;
  background-color: #fff;
  .navBar {
    display: flex;
    align-items: center;
    .nav_title {
      font-size: 36rpx;
      font-weight: 400;
      color: #000000;
      margin-left: 8rpx;
    }
  }
  .content {
    padding: 32rpx;
    .scroll_list {
      padding-bottom: 140rpx;
      .example_title {
        font-size: 52rpx;
        font-weight: 500;
        color: #333333;
      }
      .example_detail {
        font-size: 28rpx;
        font-weight: 400;
        color: #999999;
        margin: 24rpx 0 80rpx;
      }
      .image_list {
        margin-bottom: 82rpx;
        .title {
          font-size: 32rpx;
          font-weight: 400;
          color: #333333;
          margin-bottom: 32rpx;
        }
        image {
          width: 100%;
        }
      }
    }
  }
  .footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 144rpx;
    background: #FFFFFF;
    padding: 18rpx 24px 0;
    border: 1rpx solid #F3F3F3;

    display: flex;
    justify-content: space-between;
    align-items: center;

    z-index: 99;

    ::v-deep .u-button {
      width: 48%;
      margin: 0;
    }
  }
}
</style>
